<?
include 'common/header.html';
include 'common/left.html';
include 'common/autoload.php';
include 'common/Prod_Common.php';
include 'common/prodField.php';

$isedit = false;// 是否编辑进入
$lid = abs($_GET['sid']);// 景区ID
$jiutian_f = false;// 是否需要绑定九天闸机
$ticket_id = abs($_GET['prod_id']);// 产品ID，编辑进入

// 返回列表按钮
$gourl = 1;

if(!$lid && !$ticket_id) exit('<script>alert("访问参数出错");history.go(-1);</script>');
$apply_did = $_SESSION['sid'];// 供应商ID


// 身份验证
if($_SESSION['sdtype']!=9){
    if($_SESSION['dtype']==6 && $_SESSION['sdtype']!=0){
        $msg = ($_SESSION['dtype']==6) ? '您的上级不是供应商身份，无法发布产品':'您不是供应商身份，无法发布产品';
        exit('<script>alert("'.$msg.'")</script>');
    }
    $sql = "select apply_did from uu_land where id=$lid limit 1";
    $GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    if($GLOBALS['le']->f('apply_did')!=$apply_did) exit('<script>alert("这不是你的产品")</script>');
}

// 员工权限
if($_SESSION['dtype']==6 && strpos($_SESSION['qx'],'upProd')===false){
    exit('<script>alert("您无权访问这个页面")</script>');
}

$obj = new pft\Prod\Product($GLOBALS['le']);

if($ticket_id){
    $isedit = true;
    $data = ($_SESSION['sdtype']==9) ? $obj->GetTicketById($ticket_id):$obj->GetTicketById($ticket_id, $apply_did);
    $apply_did = $data['apply_did'];// 实际产品供应商ID
    $data_f = $obj->GetProdcutExt($ticket_id);//扩展表里面的数据
    $ass = '';// 集合地点
    if($data_f['ass_station']) $ass = @implode(';',unserialize($data_f['ass_station']));
    $tid = $data['id'];
    $pid = $data['pid'];
    $pobj = new Price($pid);
    $titleText = $data['title'];
    $navText = '门票编辑';
    $startplace = $data_f['startplace'];
    $endplace = $data_f['endplace'];
    $data_f['confirm_sms'] = decbin($data_f['confirm_sms']);//可能的值是 0 1 2 3 先转成2进制
    $data_f['confirm_sms'] = strlen($data_f['confirm_sms'])==2 ? $data_f['confirm_sms']:'0'.$data_f['confirm_sms'];//不足两位补0
    $data_f['cancel_sms'] = $data_f['confirm_sms'][0];//取消订单通知游客取前一位
    $data_f['confirm_sms'] = $data_f['confirm_sms'][1];//通知供应商取后一位
}

// 获取景区信息
$scenryData = $obj->GetSceneryTitle($lid);
$ptype = $scenryData['p_type'];
$notify_num = $scenryData['fax'];
if($ptype=='B' && !$ticket_id) {
    $startplace = substr($scenryData['runtime'],0,strpos($scenryData['runtime'],'|'));
    $endplace = substr($scenryData['runtime'],strpos($scenryData['runtime'],'|')+1);
}
$titleText = $scenryData['title'].'--'.$titleText;

// 按钮
if($data['sync_id'] && $data['sync_status']==2){
    $btnWrap = '同步的产品禁止修改操作';
}else{
    $btnWrap = '<button class="ui-button ui-button-lblue" id="saveTicket" type="button">保存</button>';
}

//查询是否有给绑定闸机的权限
if(!$apply_did) exit('产品供应商信息错误');
$str_ticket = "SELECT jiutian_auth FROM pft_member_extinfo WHERE fid=$apply_did limit 1";
$GLOBALS['le']->query($str_ticket);
$GLOBALS['le']->fetch_assoc();
$jiutian_auth =  $GLOBALS['le']->f('jiutian_auth');

// 需要绑定闸机的产品ID（tid）
$needBind = array(
    '1976', '4314', '4313', '5604','5603', '5523', '5522', '5521',
    '5520', '3950', '3949', '3911','5857','5818','5817','5816',
    '6047','6049','5959','5958','5957','6060','6059','6062',
    '6061','6044','6042','4313','4314','5567','7177','9746',
    '6042','6044','9833','9832','9962','10003','9962','9963',
    '9964','9965','9904','9948','9949','9901','9873','9874',
    '9862','9863','9836','9837','9855','9856','9830','9831',
    '9829','9826','9809','9810','9811','9812','10004','10392',
    '10405',
);
//print_r($data);
if($jiutian_auth == 1 || in_array($_REQUEST['prod_id'],$needBind) || $_SESSION['sid']==7132){ 
    // 绑定闸机票类数据（自己生成，九天不提供）
    $tmp = array();
    $md5 = !empty($data['uuid']) ? $data['uuid']: md5($scenryData['title'].'-'.$_REQUEST['prod_id']);
    $jiuTians[] = array('uuid'=>$md5,'name'=>$data['title']);
    $jiutian_f = true;
}

if($_SESSION['sid'] == 7517 ){// 鼓浪屿绑定闸机票类数据
    $jiuTians = file_get_contents('http://117.29.178.154:8000/et/ebusiness/ticketInfo.do');
    $jiuTians = json_decode($jiuTians,true);
    $jiuTians = $jiuTians['content'];
    $jiutian_f = true;
}
if($ptype=='F') {
	$package_data = $scenryData['attribute'];
	$package_data = $obj->PackageDataFormat($package_data);
	$pack = new PackTicket($lid);
	if(!$pack->checkEffectivePack()) exit('子票信息冲突');
	$advance = $pack->advance;// 提前天数
	$paymode = $pack->paymode;// 支付方式
	
	$saleScene = false;
	$get_account_group = "select group_id from pft_member where id={$_SESSION['sid']} limit 1";
	$GLOBALS['le']->query($get_account_group);
	$GLOBALS['le']->fetch_assoc();
	$group_id = $GLOBALS['le']->f('group_id');
	if($group_id==4){
		$saleScene = true;// 云顶允许打包现场支付
	}
	if($paymode==0 && !$saleScene) exit('现场支付不支持打包');
}
	
// 页面参数
$var['payScene'] = ($ptype=='F') ? false:true;// 允许现场支付
$var['payOnline'] = true;// 允许在线支付
if($ptype=='F' && $group_id==4 && $paymode==0){
	$var['payScene'] = true;
	$var['payOnline'] = false;
}

if($ptype=='H'){
	include '/var/www/html/new/d/module/common/Db.class.php';
	$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
	\PFT\Db::Conf($dbConf['remote_1']);
	$sql = "select id,zone_name from pft_roundzone where venue_id={$scenryData['venus_id']}";
	$venue_areas = \PFT\Db::fetchAll($sql);
}

$mpath = array(
	'H' => 'http://10.160.4.140/new/d/api/Product_check_h.php',
);

$mdetails = array(
	'H' => 1,
);

$cancel_cost_conf = false;
if($access['yd'] || $_SESSION['sid']==1433) $cancel_cost_conf = true;

$advance = 0;// 提前天数
$cancel_cost[0]= array('c_type'=>1,'c_cost'=>'','c_days'=>'');
include TPLPATH.'ticket_today.html';
include('common/footer.html');
?>